/*******************************************************************************
*   			Impacts of a Large-Scale Parenting Program: 				   *
*					Experimental Evidence from Chile						   *
********************************************************************************


	REQUIRES:	"${dt_final}panel_RR_indexes.dta"
	CREATES:	${out_tables}/T6_participation_childout.xls
				
	WRITEN BY:  Italo Lopez  [italolop@usc.edu]

********************************************************************************
	Prepare data
*******************************************************************************/

	* Load data
	use "${dt_final}panel_RR_indexes.dta", clear


	* Establish macros for regressions

/*******************************************************************************
*   Set macros for regressions
*******************************************************************************/
	
	* Outcomes
	*-----------------------------------------------------------
	local childoutcomes  "zDCCSPunt zptevir_irtscore2 zt_score zcbcl_t_e zcbcl_t_i zibatt_sspi zibatt_ssai zibatt_sssr zas_raw_score" 
	local behaviors "home_score se_score disc_score" 
	local beliefs "zpstyle1 zpstyle2 zpstyle3 zPSCS zPSSS_family zPSSS_friends zPSSS_others zPSI_Distress zCESD zpacotis"	
	
	* Controls
	*-----------------------------------------------------------

	macro  def Xvar1 "i.age_year i.gender"  	
	macro  def Xvar2 "i.age_year i.gender inc_qtaut_old i.pc_edu_mdsfin hh_mem hh_tipo"  	
	macro  def Xvar2old "i.gender inc_qtaut_old i.pc_edu_mdsfin_old hh_mem hh_tipo"  

	
	* Parental characteristics: WAIS and BFI and imputed wais 
	*-----------------------------------------------------------

	macro def parent_cha4 "BFI_ext BFI_ope BFI_con BFI_neu BFI_agr wais2 flag_wais"
	
	
/*******************************************************************************
	Table 6: IV estimates of child outcomes, with added controls
*******************************************************************************/
	

	local child "zptevir_irtscore2 zcog_index zsoc_index" 
	#delimit;
	foreach var of local child {;
				
					
				* PANEL 1: IV with Age and Gender;
					xi: xtivreg `var' $Xvar1 (treat2 treat3=group2 group3),  fe i(CENTRO_SALUD);
					estimates store `var'_iv1;
					test treat2==treat3;
					estadd scalar pb=r(p);
					
				* PANEL 2: IV plus SES and parental characteristics -; 	  
					xi: xtivreg `var' $Xvar2 $parent_cha4 (treat2 treat3=group2 group3), fe i(CENTRO_SALUD);
					estimates store `var'_iv2;
					test treat2==treat3;
					estadd scalar pb=r(p);
					
				* PANEL 3: IV plus lagged outcomes ;
					xi: xtivreg `var' $Xvar2 $parent_cha4 zchild_index_old (treat2 treat3=group2 group3), fe i(CENTRO_SALUD);
					estimates store `var'_iv3;
					test treat2==treat3;
					estadd scalar pb=r(p);
					
	};

	#delimit cr

	label var treat2 "NEP-B"
	label var treat3 "NEP-I"
	
	

	
		esttab zptevir_irtscore2_iv1 zcog_index_iv1 zsoc_index_iv1  		  /*
		*/ using "${out_tables}/T6_participation_childout.csv", replace f	  /* 
		*/ keep(treat2 treat3) 											  	  /*
		*/ cells("b(fmt(3)star)" "se(fmt(3)par)") 							  /*
		*/ star(* 0.10 ** 0.05 *** 0.01) 									  /*
		*/ stats(r2_o N pb, fmt(2 0 3) 										  /*
		*/ labels("R-squared" "Observations" "P-value NEP-B=NEP-I")) legend	  /*
		*/ mtitles("Vocabulary Index""Exec. Function Index""Socioemotional Index" ) /*
		*/ title("PANEL 1: IV with Age and Gender") 						  /* 
		*/ varlabels(treat2 "NEP-B" treat3 "NEP-I")

		esttab zptevir_irtscore2_iv2 zcog_index_iv2 zsoc_index_iv2			  /*
		*/ using "${out_tables}/T6_participation_childout.csv", append f	  /* 
		*/ keep(treat2 treat3) 											 	  /*
		*/ cells("b(fmt(3)star)" "se(fmt(3)par)") 							  /*
		*/ star(* 0.10 ** 0.05 *** 0.01) 									  /*
		*/ stats(r2_o N pb, fmt(2 0 3) 										  /*
		*/ labels("R-squared" "Observations" "P-value NEP-B=NEP-I")) legend	  /*
		*/ mtitles("Vocabulary Index""Exec. Function Index""Socioemotional Index" ) /*
		*/ title("PANEL 2: IV plus SES and parental characteristics") 		  /*
		*/ varlabels(treat2 "NEP-B" treat3 "NEP-I")
		
		
		esttab zptevir_irtscore2_iv3 zcog_index_iv3 zsoc_index_iv3         	  /*
		*/ using "${out_tables}/T6_participation_childout.csv", append f	  /* 
		*/ keep(treat2 treat3) 											 	  /*
		*/ cells("b(fmt(3)star)" "se(fmt(3)par)") 							  /*
		*/ star(* 0.10 ** 0.05 *** 0.01) 									  /*
		*/ stats(r2_o N pb, fmt(2 0 3) 										  /*
		*/ labels("R-squared" "Observations" "P-value NEP-B=NEP-I")) legend	  /*
		*/ mtitles("Vocabulary Index""Exec. Function Index""Socioemotional Index" ) /*
		*/ title(" PANEL 3: IV plus lagged outcomes") 						  /*
		*/ varlabels(treat2 "NEP-B" treat3 "NEP-I")
		
		
* End of dofile 
		
		
